package com.cardone.platform.authority.service;

import java.util.List;

import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;

import com.cardone.common.cache.Caches;
import com.cardone.common.dto.PaginationDto;
import com.cardone.platform.authority.dto.RoleDto;

/**
 * 角色服务
 *
 * @author yaohaitao
 */
public interface RoleService {
	/**
	 * spring bean id
	 */
	String BEAN_ID = "com.cardone.platform.authority.service.RoleService";

	/**
	 * 保存:角色
	 *
	 * @param mappedClass
	 *          返回类型
	 *
	 * @param saveRole
	 *          角色对象
	 *
	 * @return 角色对象
	 */
	@CacheEvict(value = { RoleService.BEAN_ID, PermissionService.BEAN_ID }, allEntries = true)
	<P> P saveByIdOrCode(final Class<P> mappedClass, final RoleDto saveRole);

	/**
	 * 保存:角色
	 *
	 * @param mappedClass
	 *          返回类型
	 *
	 * @param saveRole
	 *          角色对象
	 *
	 * @return 角色对象
	 */
	@CacheEvict(value = { RoleService.BEAN_ID, PermissionService.BEAN_ID }, allEntries = true)
	<P> P saveForPermissionIds(final Class<P> mappedClass, final RoleDto saveRole);

	/**
	 * 插入
	 *
	 * @param insertRole
	 *          角色对象
	 *
	 * @return 影响行数
	 */
	@Deprecated
	@CacheEvict(value = { RoleService.BEAN_ID, PermissionService.BEAN_ID }, allEntries = true)
	int insertByCode(final RoleDto insertRole);

	/**
	 * 删除
	 *
	 * @param ids
	 *          标识集合
	 *
	 * @return 影响行数
	 */
	@CacheEvict(value = { RoleService.BEAN_ID, PermissionService.BEAN_ID }, allEntries = true)
	int deleteByIds(final String ids);

	/**
	 * 删除
	 *
	 * @param deleteRole
	 *          角色对象
	 *
	 * @return 影响行数
	 */
	@CacheEvict(value = { RoleService.BEAN_ID, PermissionService.BEAN_ID }, allEntries = true)
	int deleteByIds(final RoleDto deleteRole);

	/**
	 * 更新
	 *
	 * @param updateRole
	 *          角色对象
	 *
	 * @return 影响行数
	 */
	@Deprecated
	@CacheEvict(value = { RoleService.BEAN_ID, PermissionService.BEAN_ID }, allEntries = true)
	int updateByCode(final RoleDto updateRole);

	/**
	 * 查询
	 *
	 * @param readRole
	 *          角色对象
	 * @return 返回数据
	 */
	@Deprecated
	@Cacheable(value = RoleService.BEAN_ID, key = Caches.KEY_1)
	Integer readByCodeNqIdForCount(final RoleDto readRole);

	/**
	 * 读取
	 *
	 * @param readRole
	 *          角色对象
	 * @return 标识
	 */
	@Cacheable(value = RoleService.BEAN_ID, key = Caches.KEY_1)
	String readIdByCode(final RoleDto readRole);

	/**
	 * 查询
	 *
	 * @param mappedClass
	 *          返回类型
	 *
	 * @param findRole
	 *          角色对象
	 * @return 返回对象
	 */
	@Cacheable(value = RoleService.BEAN_ID, key = Caches.KEY_2)
	<P> P findById(final Class<P> mappedClass, final RoleDto findRole);

	/**
	 * 查询
	 *
	 * @param mappedClass
	 *          返回类型
	 *
	 * @param findRole
	 *          角色对象
	 *
	 * @return 返回对象
	 */
	@Deprecated
	@Cacheable(value = RoleService.BEAN_ID, key = Caches.KEY_2)
	<P> P findByCodeOrId(final Class<P> mappedClass, final RoleDto findRole);

	/**
	 * 查询
	 *
	 * @param mappedClass
	 *          返回类型
	 *
	 * @param findListRole
	 *          角色对象
	 *
	 * @return 角色对象集合
	 */
	@Cacheable(value = RoleService.BEAN_ID, key = Caches.KEY_2)
	<P> List<P> findListByLikeCode(final Class<P> mappedClass, final RoleDto findListRole);

	/**
	 * 查询
	 *
	 * @param mappedClass
	 *          返回类型
	 *
	 * @param userId
	 *          用户标识
	 *
	 * @return 角色对象集合
	 */
	@Cacheable(value = RoleService.BEAN_ID, key = Caches.KEY_2)
	<P> List<P> findListByUserId(final Class<P> mappedClass, final String userId);

	/**
	 * 读取
	 *
	 * @param userId
	 *          用户标识
	 *
	 * @return 角色标识集合
	 */
	@Cacheable(value = RoleService.BEAN_ID, key = Caches.KEY_1)
	List<String> readIdListByUserId(final String userId);

	/**
	 * 分页
	 *
	 * @param mappedClass
	 *          返回类型
	 *
	 * @param paginationRole
	 *          角色对象
	 *
	 * @return 角色分页对象
	 */
	@Cacheable(value = RoleService.BEAN_ID, key = Caches.KEY_2)
	<P> PaginationDto<P> paginationByLikeCode(final Class<P> mappedClass, final RoleDto paginationRole);
}